﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ClientFrm.aspx.cs" Inherits="WebApp.ClientFrm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>客户信息</title>
    <link rel="stylesheet" type="text/css" href="css/newStyle.css" />
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.3.2/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.3.2/themes/icon.css" />

    <script type="text/javascript" src="js/common.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/jquery-1.8.0.min.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/jquery.easyui.min.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/locale/easyui-lang-zh_CN.js"></script>

    <script type="text/javascript">
        var PageSize = 20;
        //页面加载
        $(window).load(function() {
            initData();
            initGrid();
        });

        $(window).resize(function() {
            $('#tb').datagrid('resize');
        });

        function doSearch(pageNumber) {
            if (pageNumber > 0)
                pageNumber = pageNumber - 1; //从0开始
            var params = getParams(pageNumber);
            $('#tb').datagrid('reload', params);
        }


        function getParams(pageNumber) {
            return $.extend({}, {
                DataType: 'Client',
                Name: $('#qName').val(),
                ContactMan: $('#qContactMan').val(),
                Tel: $('#qTel').val(),
                Address: $('#qAddress').val(),
                pageSize: PageSize,
                pageIndex: pageNumber
            });
        }

        function booleanFormat(val, rec) {
            if (val == true) {
                return "是";
            }
            else {
                if (val == false)
                    return "否";
                else
                    return val;
            }
        }

        //加载表格datagrid
        function initGrid() {

            var params = getParams(0);

            //加载数据
            $('#tb').datagrid({
                toolbar: '#searchBar',
                width: 'auto',
                fit: true,
                fitColumns: true,
                height: 'auto',
                striped: true,
                singleSelect: true,
                url: 'JSONHandler.ashx',
                queryParams: params,
                loadMsg: '数据加载中请稍后……',
                pagination: true,
                rownumbers: true,
                columns: [[
        { field: 'id', title: '编号', align: 'center', hidden: true },
        { field: 'fullName', title: '客户全称', align: 'center' },
        { field: 'shortName', title: '客户简称', align: 'center' },
        { field: 'contactMan', title: '联系人', align: 'center' },
        { field: 'tel', title: '联系电话', align: 'center' },
        { field: 'fax', title: '传真号码', align: 'center' },
        { field: 'address', title: '联系地址', align: 'center' }
    ]], onDblClickRow: function(rowIndex, rowData) {
        editClient();
    }, loadFilter: function(data) {
        if (data)
            return data;
        else
            return { "total": 0, "rows": [] };
    }
            });

            $('#tb').datagrid('getPager').pagination({
                pageSize: PageSize, //每页显示的记录条数，默认为10   
                pageList: [10, 20, 30, 40, 50], //可以设置每页记录条数的列表   
                beforePageText: '第', //页数文本框前显示的汉字   
                afterPageText: '页    共 {pages} 页',
                displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
                onBeforeRefresh: function() {
                },
                onRefresh: function(pageNumber, pageSize) {
                },
                onChangePageSize: function(pageSize) {
                    PageSize = pageSize;
                },
                onSelectPage: function(pageNumber, pageSize) {
                    doSearch(pageNumber);
                }
            });

        }

        function initData() {

        }

        function resetAll() {
            $('#fm').form('clear');
        }

        function addClient() {
            openWin('EditClientFrm.aspx', "新增客户资料", 600, 400);
        }

        function editClient() {
            var row = $('#tb').datagrid('getSelected');
            if (row) {
                var ClientId = row.id;
                if (ClientId)
                    openWin('EditClientFrm.aspx?ClientId=' + ClientId, "编辑客户资料", 600, 400);
            }
        }

        function deleteClient(id) {
            var row = $('#tb').datagrid('getSelected');
            if (row) {
                $.messager.confirm('提示', '确认删除该项吗?', function(r) {
                    if (r) {
                        WebApp.ClientFrm.DeleteClient(row.id, function callback(p) {

                            if (p.error) {
                                $.messager.alert('异常消息', '提交删除异常,' + p.error.Message, 'error');
                                return;
                            }
                            var res = p.value;
                            if (res) {
                                var data = res.Data;
                                var msg = res.Msg;
                                if (msg)
                                    $.messager.alert('删除异常', msg, 'error');
                                else {
                                    if (data == true) {
                                        $.messager.alert('消息', '信息已删除!', 'info');
                                        doSearch();
                                    }
                                    else
                                        $.messager.alert('删除失败', msg, 'error');
                                }
                            }
                        });
                    }
                });
            }
        }


        function openWin(url, title, width, height) {
            $('#winFrame').prop('src', url);
            $('#winFrame').prop('style').height = height + 'px';
            $('#winFrame').prop('style').width = width + 'px';
            $('#win').window({
                title: title,
                width: width + 'px',
                height: height + 'px',
                modal: true
            });
        }      
    </script>

</head>
<body style="padding: 5px">
    <form id="form1" runat="server">
    </form>
    <div id="searchBar" style="padding: 5px; height: auto">
        <form id="fm" style="padding: 0; margin: 0">
        <span>名称：</span><input type="text" style="width: 100px" id="qName">
        <span>联系人：</span><input type="text" style="width: 100px" id="qContactMan">
        <span>电话：</span><input type="text" style="width: 100px" id="qTel">
        <span>地址：</span><input type="text" style="width: 100px" id="qAddress">
        <a href="#" class="easyui-linkbutton" iconcls="icon-search" plain="true" onclick="doSearch();">
            搜索</a> <a href="#" class="easyui-linkbutton" iconcls="icon-undo" plain="true" onclick="resetAll();">
                重置</a> <a href="#" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="addClient();">
                    新增</a> <a href="#" class="easyui-linkbutton" iconcls="icon-remove" plain="true" onclick="deleteClient();">
                        删除</a></form>
    </div>
    <table id="tb" class="easyui-datagrid">
    </table>
    <div id="win">
        <iframe id="winFrame" src="" style="width: 0px; height: 0px" frameborder="0" scrolling="no">
        </iframe>
    </div>
</body>
</html>
